<template>
  <div id="wrap">
    <!--头部-->
    <HeaderTwo></HeaderTwo>
    <!--轮播图-->
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide"><img src="../../assets/shortProduct/bigImg.png" alt=""></div>
        <div class="swiper-slide"><img src="../../assets/shortProduct/bigImg.png" alt=""></div>
        <div class="swiper-slide"><img src="../../assets/shortProduct/bigImg.png" alt=""></div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>
    </div>
    <!--商品详情-->
    <ul id="product-first">
      <li v-for="obj in aProduct">
        <div class="product" @click="doClick(obj)">
          <div class="productImg">
            <img :src="obj.img" alt="">
          </div>
          <span class="product-title">{{obj.name}}</span>
          <span class="product-price">¥{{obj.price}}</span>
          <span class="line-h"></span>
          <span class="line-v"></span>
        </div>
        <span class="product-num">还剩下{{obj.surplus}}件</span>
        <span class="once" @click="goTo(obj)">马上去抢</span>
      </li>
      <div class="bottom-f"></div>
    </ul>
    <my-footer></my-footer>
  </div>
</template>
<script>
  import Vue from 'vue'
  import HeaderTwo from '../home/MyHeader/HeaderTwo.vue'
  import * as $ from 'jquery'
  import * as Swiper from 'swiper'
  import "../../../node_modules/swiper/dist/css/swiper.css";
  import MyFooter from '../home/MyFooter/MyFooter.vue'
  import 'swiper/dist/css/swiper.css'
  export default {
    data() {
        return {
          isPrice: true,
          aProduct:[]
        }
    },
    components: {
      HeaderTwo,
      MyFooter
    },
    // 轮播图
    mounted() {
      new Swiper['default'] ('.swiper-container', {
        speed:300,
        autoplay : {
          delay:3000
        },
        loop: true,
        pagination: {
          el: '#wrap .swiper-pagination',
          type: 'bullets',
          clickable :true
//          bulletElement:'li'
//          type: 'custom'
//          bulletActiveClass: 'my-bullet-active'
        }
      });
    },
    methods:{
      doClick(obj) {
        this.$router.push({name:'productDetail',params: {id:obj.ID,isPrice: this.isPrice}});
        console.log(obj.ID);
      },
      goTo(obj) {
        this.isPrice = false;
        this.$router.push({name:'productDetail',params: {id:obj.ID,isPrice: this.isPrice}});
      }
    },
    created(){
      Vue.axios.post('/goods/short').then((res)=>{
        console.log('ccc');
        console.log(res.data);
        this.aProduct = res.data;

      })
    }
  }
</script>
<style scoped>
  /*@import "../../../node_modules/swiper/dist/css/swiper.css";*/
  .swiper-container {
    width: 100%;
    height: 15rem;
  }

  .swiper-container img{
    width:100%;
    height: 100%;
  }
  .swiper-pagination-bullet-active{
    background-color: red;
  }
  #wrap ul>li{
    width:calc(100% / 3);
    height:17.85rem;
    display: inline-block;
  }
  .product{
    width: 100%;
    height:12.7rem;
    position: relative;
  }
  .productImg{
    width: 100%;
    text-align: center;
    margin-top: 1rem;
    font-size: 0;
    margin-bottom: 1rem;
  }
  .productImg img{
    height:7.65rem;
  }
  .product-title, .product-price{
    display: block;
    width: 100%;
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    color: #808080;
  }
  .product-price{
    margin-top: 0.5rem;
    color:  #e83d41;
  }
  .product-num{
    display: block;
    width: 100%;
    text-align: center;
    font-size: 0.9rem;
    color: #4d4d4d;
    margin-bottom: 0.5rem;
  }
  .once{
    display: block;
    width:6.8rem;
    height: 1.5rem;
    color: white;
    font-size: 1rem;
    line-height: 1.5rem;
    text-align: center;
    background-color: #e53e42;
    border-radius: 0.75rem;
    margin-left: calc(50% - 3.4rem);
  }
  .line-h{
    display: block;
    width: 9rem;
    margin-left:calc(50% - 4.5rem);
    border-bottom: 1px solid #cccccc;
  }
  .line-v{
    display: block;
    height: 8.5rem;
    border-left: 1px solid #cccccc;
    position: absolute;
    top:calc(50% - 4.75rem);
    right: 0;
  }
  #wrap ul>li:nth-child(3n) .line-v{
    display: none;
  }
  .bottom-f{
    width: 100%;
    height: 2rem;
    border-top: 1px solid #cccccc;
    box-shadow: 0px 1px 0px 0px
    #cccccc;
    background-color: rgb(242,242,242);
  }
</style>
